package com.bbx.taxi.client.Task;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import com.bbx.api.sdk.model.comm.returns.line.Cities;
import com.bbx.api.sdk.model.passanger.SvconfigBuild;
import com.bbx.api.sdk.net.base.BaseNetwork;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.config.conn.GetLineNet;
import com.bbx.api.util.LogUtils;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Message.ObserverListener.DATA_TYPE;
import com.bbx.taxi.client.DB.LineDB;

public class MyLineTask extends BaseTask{
    public DATA_TYPE TYPE=DATA_TYPE.LINE;
    private SvconfigBuild mSvconfigBuild;
    private LineDB db_line;
    private boolean isShow;
	public MyLineTask(Activity context,boolean isShow) {
		super(context);
		db_line=new LineDB();
		this.isShow=isShow;
		SvconfigBuild mSvconfigBuild = new SvconfigBuild(context);
		mSvconfigBuild.version=0;
	}
	@Override
	public boolean isShow() {
		return isShow;
	}

	@Override
	public boolean isReturnString() {
		return true;
	}
	@Override
	public boolean condition() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public void request() {
		setType(TYPE,mSvconfigBuild);
	}
	@Override
	public void success(int status,Object object) {
		if(object!=null){
			try {
				JSONObject JO=new JSONObject((String)object);
				db_line.onDelete();
				JSONArray  ja_cities=JO.getJSONArray("cities");
//				List<String> list_line=new ArrayList<String>();
//				List<String> list_line_cn=new ArrayList<String>();
//				//室内
//				List<String> list_incity_type=new ArrayList<String>();
//				List<String> list_incity_phone=new ArrayList<String>();
//				List<String> list_incity_cn=new ArrayList<String>();
//				List<String> list_incity_line=new ArrayList<String>();
//				for (int i = 0; i < ja_cities.length(); i++) {
//					JSONObject jo = new JSONObject(ja_cities.get(i).toString());
//					String name=jo.getString("name");
//					String cn_name=jo.getString("cn_name");
//					Cities cities = (Cities) new JsonBuild().getData(Cities.class,
//							jo.toString());
//					String incity=Value.CITY_NOINCITY;
//					if(cities!=null&&cities.getIs_city().equals(Value.CITY_INCITY)&&cities.getTo_CityList()!=null&&
//							!cities.getTo_CityList().isEmpty()&&cities.getTo_CityList().get(0).getIs_incity().equals(Value.CITY_INCITY)){
//						incity=Value.CITY_INCITY;
//					}
//
//					db_line.onWrite(name, cn_name, incity,jo.toString());
//				}
//				    /**全部路线*/
//					ArrayList<To_Cities> to_citylist=db_line.readToCityDB(cn_name,false);
//					if (to_citylist != null){
//		    			for(int j=0;j<to_citylist.size();j++){
//		    			    list_line.add(to_citylist.get(j).getLine_id());	
//		    			    list_line_cn.add(String.format(context.getString(R.string.line_to_line), cn_name,to_citylist.get(j).getCn_Name()));
//		    			    }
//		    			}
//					/**市内*/
//					ArrayList<To_Cities> to_citylist_sn=db_line.readToCityDB(cn_name,true);
//					if(to_citylist_sn!=null){
//						for(int j=0;j<to_citylist_sn.size();j++){
//		    			    //是市内城市
//		    			    if(to_citylist_sn.get(j).getIs_incity()!=null){
//		    			    if(to_citylist_sn.get(j).getIs_incity().equals(Value.CITY_INCITY)&&to_citylist_sn.get(j).getCn_Name().equals(cn_name)){
//		    			    	list_incity_line.add(to_citylist_sn.get(j).getLine_id());
//		    			    	list_incity_type.add(to_citylist_sn.get(j).getIncity_type());	
//		    			    	list_incity_phone.add(to_citylist_sn.get(j).getIncity_phone());	
//		    			    	list_incity_cn.add(to_citylist_sn.get(j).getCn_Name());
//		    			    }
//		    			    }
//		    			}
//					}
//				}
//				//存储线路
//				SharedPreUtil.putStringValue(context,SharedPreEncryptUtil.list_line_num,list_line.toString().trim());
//				SharedPreUtil.putStringValue(context,SharedPreEncryptUtil.list_line_cn,list_line_cn.toString().trim());
//				//市内城市
//				SharedPreUtil.putStringValue(context,SharedPreEncryptUtil.list_incity_phone,list_incity_phone.toString().trim());
//				SharedPreUtil.putStringValue(context,SharedPreEncryptUtil.list_incity_type,list_incity_type.toString().trim());
//				SharedPreUtil.putStringValue(context,SharedPreEncryptUtil.list_incity_cn,list_incity_cn.toString().trim());
//				SharedPreUtil.putStringValue(context,SharedPreEncryptUtil.list_incity_num,list_incity_line.toString().trim());
			} catch (JSONException e) {
			}
		}
	
	}
	@Override
	public void failed(int status, String msg,String message) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public BaseNetwork getBaseNetwork() {
		return new GetLineNet(context);
	}
}
